function seg = grabcut_exec(img_patch, mask, ls_patch)

% * __trimap__ uint8 H-by-W array of labels
%            {0:bg, 1:fg, 2:probably-bg, 3:probably-fg}
if nargin==3 
    way = 1;
elseif nargin == 2
    if(numel(mask)==4)
        way =2; 
    else
        way =3;
    end
    
end

if way == 1
    snuz     =   size(ls_patch);
    unsure_bg   =   ls_patch&(mask<0.51);

    trimap  =   zeros(siz, 'uint8');

    m       =   mask==1;
    trimap(m)   =   1;
    m       =   mask==0.75;
    trimap(m)   =   3;
    m       =   mask==0.5;
    trimap(m)   =   2;
    m       =   mask<=0.25;
    trimap(m)   =   0;

    trimap(unsure_bg) = 3;

    seg = cv.grabCut(uint8(img_patch), trimap,'Init','Mask');


elseif way ==2 
    seg  = cv.grabCut(uint8(img_patch),mask,'Init','Rect');   
elseif way ==3
    seg = cv.grabCut(uint8(img_patch), uint8(mask),'Init','Mask');    
end


    m = seg == 1;
    seg(m)   =   4;
    m = seg == 0;
    seg(m)   =   1;
    seg = seg - 1;



